package logic

import (
	"context"
	"week1/goodrpc/goodrpcclient"

	"week1/api/internal/svc"
	"week1/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AuthUserLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAuthUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AuthUserLogic {
	return &AuthUserLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AuthUserLogic) AuthUser(req *types.AuthUserRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	auth, err := l.svcCtx.GoodRpc.AuthUser(l.ctx, &goodrpcclient.AuthUserRequest{
		UserId:   req.UserId,
		RealName: req.RealName,
		IdCard:   req.IdCard,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}
	return &types.Response{
		Message: "实名认证成功",
		Data:    auth,
		Code:    200,
	}, nil
}
